
package com.insigma.business.qrcode.soldier.service.impl;



import com.insigma.business.qrcode.common.service.SequenceGenerator;
import com.insigma.business.qrcode.common.util.BizCheckUtil;
import com.insigma.business.qrcode.common.vo.ProcessStatusEnum;
import com.insigma.business.qrcode.soldier.dao.PlacementSoldierInfoDao;
import com.insigma.business.qrcode.soldier.dto.PlacementSoldierInfoBSearcher;
import com.insigma.business.qrcode.soldier.dto.SequenceNameConstant;
import com.insigma.business.qrcode.soldier.entity.PlacementSoldierInfoDO;
import com.insigma.business.qrcode.soldier.service.PlacementBatchService;
import com.insigma.business.qrcode.soldier.service.PlacementSoldierInfoService;
import org.apache.commons.httpclient.util.DateUtil;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;


@Service("placementSoldierInfoService")
public class PlacementSoldierInfoServiceImpl implements PlacementSoldierInfoService {

    @Autowired(required = false)
    private PlacementSoldierInfoDao placementSoldierInfoDao;

    @Autowired
    private PlacementBatchService placementBatchService;

    @Autowired(required = false)
    private SequenceGenerator sequenceGenerator;

    
    @Override
    public List<PlacementSoldierInfoDO> search(final PlacementSoldierInfoBSearcher placementSoldierInfoBSearcher) {
        if (Strings.isBlank(placementSoldierInfoBSearcher.getYear())) {
            String year = DateUtil.formatDate(new Date(), "yyyy");
            placementSoldierInfoBSearcher.setYear(year);
        }










        return placementSoldierInfoDao.search(placementSoldierInfoBSearcher);
    }
   
    @Override
    public PlacementSoldierInfoDO get(final String id){
        return placementSoldierInfoDao.get(id);
    }

    
    @Override
    public Integer insert(final PlacementSoldierInfoDO placementSoldierInfoDO){
        placementSoldierInfoDO.setId(sequenceGenerator.genKey(SequenceNameConstant.PLACEMENT_SOLDIER_INFO_ID));
        return placementSoldierInfoDao.insert(placementSoldierInfoDO);
    }

    
    @Override
    public Integer update(final PlacementSoldierInfoDO placementSoldierInfoDO){
        return placementSoldierInfoDao.update(placementSoldierInfoDO);
    }

    
    @Override
    public Integer delete(final String id, final String modifierType, final String modifierId){
        return placementSoldierInfoDao.delete(id,modifierType,modifierId);
    }

    @Override
    public PlacementSoldierInfoDO getByPlacementIdAndIdCardNo(String placementId, String idCardNo) {
        return placementSoldierInfoDao.getByPlacementIdAndIdCardNo(placementId,idCardNo, null);
    }

    @Override
    public PlacementSoldierInfoDO getByPlacementIdAndMobile(String placementId, String mobile) {
        return placementSoldierInfoDao.getByPlacementIdAndIdCardNo(placementId,null, mobile);
    }

    @Override
    public PlacementSoldierInfoDO getBySoldierId(String soldierId) {
        return placementSoldierInfoDao.getBySoldierId(soldierId);
    }

    @Override
    public PlacementSoldierInfoDO getByIdCardNo(String idCardNo) {
        return placementSoldierInfoDao.getByIdCardNo(idCardNo);
    }

    @Override
    public List<String> listSoldierIdsOrderByRank(String placementId) {
        return placementSoldierInfoDao.listSoldierIdsOrderByRank(placementId);
    }

    @Override
    public List<String> listIdCardNoOrderByRank(String placementId) {
        return placementSoldierInfoDao.listIdCardNoOrderByRank(placementId);
    }

    @Override
    public List<PlacementSoldierInfoDO> listAllNotRecruitSoldier(String placementId) {
        return  placementSoldierInfoDao.listAllNotRecruitSoldier(placementId);
    }

    @Override
    public PlacementSoldierInfoDO getByMobile(String mobile) {
        return placementSoldierInfoDao.getByMobile(mobile);
    }

    @Override
    public List<PlacementSoldierInfoDO> listByBatchId(String batchId) {
        BizCheckUtil.checkNotNull(batchId, "batchId不能为空");
        return placementSoldierInfoDao.listByBatchId(batchId);
    }

    @Override
    public String getIdCardNoBySoldierId(String soldierId) {
        BizCheckUtil.checkNotBlank(soldierId, "soldierId不为空");
        PlacementSoldierInfoDO bySoldierId = placementSoldierInfoDao.getBySoldierId(soldierId);
        BizCheckUtil.checkNotNull(bySoldierId, "查无此人");
        return bySoldierId.getIdCardNo();
    }

    @Override
    public Integer count(PlacementSoldierInfoBSearcher placementSoldierInfoBSearcher) {
        if (Strings.isBlank(placementSoldierInfoBSearcher.getYear())) {
            String year = DateUtil.formatDate(new Date(), "yyyy");
            placementSoldierInfoBSearcher.setYear(year);
        }
        List<PlacementSoldierInfoDO> search = placementSoldierInfoDao.search(placementSoldierInfoBSearcher);
        return Long.valueOf(placementSoldierInfoBSearcher.getTotalCount()).intValue();
    }

    @Override
    public Integer publishAllSoldier(String placementId, String modifierId, String modifierType) {
        return placementSoldierInfoDao.publishAllSoldier(placementId, modifierId, modifierType);
    }

    @Override
    public List<PlacementSoldierInfoDO> listByPositionId(String positionId) {
        return placementSoldierInfoDao.listByPositionId(positionId);
    }

    @Override
    public List<PlacementSoldierInfoDO> listShortInfoByPlacement(String placementId) {
        return placementSoldierInfoDao.listShortInfoByPlacement(placementId);
    }

    @Override
    public Integer countSuccess(PlacementSoldierInfoBSearcher placementSoldierInfoBSearcher) {
        if (Strings.isBlank(placementSoldierInfoBSearcher.getYear())) {
            String year = DateUtil.formatDate(new Date(), "yyyy");
            placementSoldierInfoBSearcher.setYear(year);
        }
         return placementSoldierInfoDao.countSuccess(placementSoldierInfoBSearcher);
    }

    @Override
    public Boolean checkPass(String idCardNo, String checkType) {
        PlacementSoldierInfoDO byIdCardNo = getByIdCardNo(idCardNo);
        String placementStatus = byIdCardNo.getPlacementStatus();
        String s = checkType + "_h_" + ProcessStatusEnum.SUCCESS.name();
        return placementStatus.contains(s);
    }

    @Override
    public List<PlacementSoldierInfoDO> listSoldierByPositionBatch(String batchId) {
        return placementSoldierInfoDao.listSoldierByPositionBatch(batchId);
    }

    @Override
    public PlacementSoldierInfoDO getByName(String realName, String placementId) {
        return placementSoldierInfoDao.getByName(realName, placementId);
    }


}
